home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / lex.h < prev    next >
C/C++ Source or Header  |  1997-03-07  |  5KB  |  205 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_lex_h)
  24. #define octave_lex_h 1
  25.  
  26. // Arrange to get input via readline.
  27.  
  28. #ifdef YY_INPUT
  29. #undef YY_INPUT
  30. #endif
  31. #define YY_INPUT(buf,result,max_size) \
  32.   if ((result = octave_read (buf, max_size)) < 0) \
  33.     YY_FATAL_ERROR ("octave_read () in flex scanner failed");
  34.  
  35. // Try to avoid crashing out completely on fatal scanner errors.
  36.  
  37. #ifdef YY_FATAL_ERROR
  38. #undef YY_FATAL_ERROR
  39. #endif
  40. #define YY_FATAL_ERROR(msg) \
  41.   do \
  42.     { \
  43.       error (msg); \
  44.       jump_to_top_level (); \
  45.     } \
  46.   while (0)
  47.  
  48. #define TOK_RETURN(tok) \
  49.   do \
  50.     { \
  51.       current_input_column += yyleng; \
  52.       lexer_flags.quote_is_transpose = 0; \
  53.       lexer_flags.cant_be_identifier = 0; \
  54.       lexer_flags.convert_spaces_to_comma = 1; \
  55.       return (tok); \
  56.     } \
  57.   while (0)
  58.  
  59. #define TOK_PUSH_AND_RETURN(name,tok) \
  60.   do \
  61.     { \
  62.       yylval.tok_val = new token (name, input_line_number, \
  63.                   current_input_column); \
  64.       token_stack.push (yylval.tok_val); \
  65.       TOK_RETURN (tok); \
  66.     } \
  67.   while (0)
  68.  
  69. #define BIN_OP_RETURN(tok,convert) \
  70.   do \
  71.     { \
  72.       yylval.tok_val = new token (input_line_number, current_input_column); \
  73.       token_stack.push (yylval.tok_val); \
  74.       current_input_column += yyleng; \
  75.       lexer_flags.quote_is_transpose = 0; \
  76.       lexer_flags.cant_be_identifier = 0; \
  77.       lexer_flags.convert_spaces_to_comma = convert; \
  78.       return (tok); \
  79.     } \
  80.   while (0)
  81.  
  82. // XXX FIXME XXX -- these input buffer things should be members of an
  83. // parser input stream class.
  84.  
  85. typedef struct yy_buffer_state *YY_BUFFER_STATE;
  86.  
  87. // Associate a buffer with a new file to read.
  88. extern YY_BUFFER_STATE create_buffer (FILE *f);
  89.  
  90. // Report the current buffer.
  91. extern YY_BUFFER_STATE current_buffer (void);
  92.  
  93. // Connect to new buffer buffer.
  94. extern void switch_to_buffer (YY_BUFFER_STATE buf);
  95.  
  96. // Delete a buffer.
  97. extern void delete_buffer (YY_BUFFER_STATE buf);
  98.  
  99. // Restore a buffer (for unwind-prot).
  100. extern void restore_input_buffer (void *buf);
  101.  
  102. // Delete a buffer (for unwind-prot).
  103. extern void delete_input_buffer (void *buf);
  104.  
  105. // See if a function file has extra garbage after the end statement.
  106. // This needs to be defined in lex.l so that it can use yyinput() but
  107. // it must be called from parse.y.
  108. extern void check_for_garbage_after_fcn_def (void);
  109.  
  110. // For communication between the lexer and parser.
  111.  
  112. class lexical_feedback
  113. {
  114. public:
  115.  
  116.   lexical_feedback (void) { init (); }
  117.  
  118.   ~lexical_feedback (void) { }
  119.  
  120.   void init (void);
  121.  
  122.   // Nonzero means we think we are looking at the beginning of a
  123.   // function definition.
  124.   int beginning_of_function;
  125.  
  126.   // Brace level count.
  127.   int braceflag;
  128.  
  129.   // Another context hack, this time for the plot command's `using',
  130.   // `title', and `with' keywords.
  131.   int cant_be_identifier;
  132.  
  133.   // Nonzero means that we should convert spaces to a comma inside a
  134.   // matrix definition.
  135.   int convert_spaces_to_comma;
  136.  
  137.   // Nonzero means we're in the middle of defining a function.
  138.   int defining_func;
  139.  
  140.   // Nonzero means we're parsing the return list for a function.
  141.   int looking_at_return_list;
  142.  
  143.   // Nonzero means we're parsing the parameter list for a function.
  144.   int looking_at_parameter_list;
  145.  
  146.   // GAG.  Stupid kludge so that [[1,2][3,4]] will work.
  147.   int do_comma_insert;
  148.  
  149.   // Nonzero means we think we are looking at a set command.
  150.   int doing_set;
  151.  
  152.   // Nonzero means we're looking at the range part of a plot command.
  153.   int in_plot_range;
  154.  
  155.   // Nonzero means we're looking at the using part of a plot command.
  156.   int in_plot_using;
  157.  
  158.   // Nonzero means we're looking at the style part of a plot command.
  159.   int in_plot_style;
  160.  
  161.   // Nonzero means we're looking at an indirect reference to a
  162.   // structure element.
  163.   int looking_at_indirect_ref;
  164.  
  165.   // Nonzero means we're in the middle of defining a loop.
  166.   int looping;
  167.  
  168.   // Nonzero means we need to do some extra lookahead to avoid being
  169.   // screwed by bogus function syntax.
  170.   int maybe_screwed;
  171.  
  172.   // Nonzero means we need to do some extra lookahead to avoid being
  173.   // screwed by bogus function syntax.
  174.   int maybe_screwed_again;
  175.  
  176.   // Nonzero means we've seen something that means we must be past the
  177.   // range part of a plot command.
  178.   int past_plot_range;
  179.  
  180.   // Nonzero means we're working on a plot command.
  181.   int plotting;
  182.  
  183.   // Return transpose or start a string?
  184.   int quote_is_transpose;
  185.  
  186. private:
  187.  
  188.   lexical_feedback (const lexical_feedback&);
  189.  
  190.   lexical_feedback& operator = (const lexical_feedback&);
  191. };
  192.  
  193. // Flags that need to be shared between the lexer and parser.
  194. extern lexical_feedback lexer_flags;
  195.  
  196. extern void symbols_of_lex (void);
  197.  
  198. #endif
  199.  
  200. /*
  201. ;;; Local Variables: ***
  202. ;;; mode: C++ ***
  203. ;;; End: ***
  204. */
  205.